#ifndef UTILS_H
#define UTILS_H

#include <tinyxml2/tinyxml2.h>
#include <string>
#include <vector>

struct ResultDesc
{
    ResultDesc(int res, std::string desc)
        : res(res), errDesc(std::move(desc))
    {}

    int res{0};//0表示成功，非0表示失败
    std::string errDesc;
};

class Utils
{
public:
    Utils();

    /**
     * @brief:  将传入的xml元素格式化成xml字符串
     */
    static std::string formatElement(const tinyxml2::XMLElement *element);

    /**
     * @brief:  创建一个新进程，并返回进程pid
     */
    static ResultDesc createProcess(pid_t *pid, const std::string &process, const std::string &argv, bool printScreen);
    static ResultDesc createProcess(pid_t *pid, const std::string &process, const std::string &argv, const std::vector<std::string>& env_strings, bool printScreen);

    static std::string getLastComponent(const std::string &path);

    /**
     * @brief:  判断字符串类型
     */
    static bool isBool(const std::string &str);
    static bool isInt(const std::string &str);
    static bool isDouble(const std::string &str);

    static bool isRelease();
};


#endif //UTILS_H
